/// 发送好友申请请求模型
class SendFriendRequestRequest {
  final int senderId;
  final int receiverId;
  final String? message;
  final int free; // 0=收费，1=免费
  final int timestamp;

  SendFriendRequestRequest({
    required this.senderId,
    required this.receiverId,
    this.message,
    this.free = 0,
    int? timestamp,
  }) : timestamp = timestamp ?? DateTime.now().millisecondsSinceEpoch ~/ 1000;

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = {
      'sender_id': senderId,
      'receiver_id': receiverId,
      'free': free,
      'timestamp': timestamp,
    };
    
    if (message != null && message!.isNotEmpty) {
      data['message'] = message;
    }
    
    return data;
  }
}

/// 发送好友申请响应模型
class SendFriendRequestResponse {
  final String status;
  final String message;
  final int? requestId;
  final int? pointsChange;

  SendFriendRequestResponse({
    required this.status,
    required this.message,
    this.requestId,
    this.pointsChange,
  });

  bool get isSuccess => status == 'success';

  factory SendFriendRequestResponse.fromJson(Map<String, dynamic> json) {
    return SendFriendRequestResponse(
      status: json['status'] ?? 'error',
      message: json['message'] ?? '未知错误',
      requestId: json['request_id'],
      pointsChange: json['pointsChange'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'status': status,
      'message': message,
      if (requestId != null) 'request_id': requestId,
      if (pointsChange != null) 'pointsChange': pointsChange,
    };
  }
}
